﻿namespace Swimj.Core.Extensions
{
    public static class DateTimeExtensions
    {
        public static string? DateToString(this DateTime date)
        {
            return DateToString(date, null);
        }

        public static string? DateToString(this DateTime date, string? nullString)
        {
            if (date == DateTime.MinValue)
            {
                return nullString;
            }
            return date.ToString("yyyy-MM-dd");
        }

        public static string? DateToStringH(this DateTime date)
        {
            return DateToStringH(date, null);
        }

        public static string? DateToStringH(this DateTime date, string? nullString)
        {
            if (date == DateTime.MinValue)
            {
                return nullString;
            }
            return date.ToString("yyyy-MM-dd HH");
        }

        public static string? DateToStringM(this DateTime date)
        {
            return DateToStringM(date, null);
        }

        public static string? DateToStringM(this DateTime date, string? nullString)
        {
            if (date == DateTime.MinValue)
            {
                return nullString;
            }
            return date.ToString("yyyy-MM-dd HH:mm");
        }

        public static string? DateToStringL(this DateTime date)
        {
            return DateToStringL(date, null);
        }

        public static string? DateToStringL(this DateTime date, string? nullString)
        {
            if (date == DateTime.MinValue)
            {
                return nullString;
            }
            return date.ToString("yyyy-MM-dd HH:mm:ss");
        }

        public static DateTime StartDate(this DateTime date)
        {
            return new DateTime(date.Year, date.Month, date.Day, 0, 0, 0);
        }

        public static DateTime EndDate(this DateTime date)
        {
            return new DateTime(date.Year, date.Month, date.Day, 23, 59, 59, 999);
        }

        public static long GetTime(this DateTime time)
        {
            return (time.Ticks - new DateTime(1970, 1, 1).Ticks) / 10000;
        }
    }
}
